package com.frxuexi.park2212.payment

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.lib_base.entity.PayBeanItem
import com.frxuexi.lib_base.net.Const
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityAddPayProjectBinding
import dagger.hilt.android.AndroidEntryPoint
import java.util.Calendar

@Route(path = "/app/AddPayProjectActivity")
@AndroidEntryPoint
class AddPayProjectActivity : BaseActivity<ActivityAddPayProjectBinding, PayViewModel>() {
    override fun initData() {
        vm.addPay.observe(this) {
            Log.i("===", it.toString())
            ToastUtils.showLong("操作成功")
        }
    }

    override fun initView() {
        binding.headAddcharge.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("新增收费")
            headerAdd.setImageResource(R.drawable.ic_action_ok)
            headerAdd.setOnClickListener {
                val money = binding.chargeMoney.text.toString().toInt()
                val project = binding.chargeProject.text.toString()
                val phone = binding.chargePhone.text.toString().toLong()
                val uid = binding.chargeUname.text.toString().toInt()
                val calendar = Calendar.getInstance()
                calendar.add(Calendar.DAY_OF_MONTH, 1)
                val item = PayBeanItem(
                    0, 0, money, project, phone, 0,
                    vm.getDate(System.currentTimeMillis()), vm.getDate(calendar.timeInMillis),
                    null, SPUtils.getInstance().getString(Const.USERNAME), uid, "", "",
                    "未缴费", "", 0, money
                )
                vm.addPay(item)
            }
        }
    }

}